---
title: "README – Data and Code for 'From the Factory Floor to the Ballot Box: Firm-Based Origins of Brazil's Populist Right'"
output: github_document
---

This repository contains the data and code necessary to replicate the results presented in the paper *"From the Factory Floor to the Ballot Box: Firm-Based Origins of Brazil's Populist Right."* The analysis combines matched employer-employee data from Brazil’s RAIS dataset with original survey and experimental data collected online.

## Workflow Overview

All data processing and model estimation steps are structured for reproducibility. The workflow is divided into three main components:

### 1. Administrative Data (RAIS + Apoios Matching)

- The full process of merging Brazil’s RAIS administrative dataset with the list of Bolsonaro party supporters (`Apoios`) is managed via the `Snakefile` provided in the repository.
- The workflow is executed using **Snakemake**, a Python-based reproducibility framework for scientific workflows.
- The associated Python scripts handle:
  - Matching RAIS and Apoios records
  - Constructing comparison groups
  - Generating industry-, occupation-, and education-specific variables

### 2. RAIS-Based Statistical Models and Outputs

- Script: `rais_models_paper.R`  
  This R script runs all models using the RAIS data and generates the corresponding figures and tables used in the paper.

**Tables:**
- `rais_aliados_diff.tex` – TWFE models comparing wage decline among Bolsonaro supporters and controls  
- `rais_aliados_post.tex` – Summary statistics and post-treatment differences  
- `rais_aliados_inpc_diff.tex` – Robustness checks with regional inflation adjustments

**Figures:**
- `remmedia_dif_educ_diff.png` – Wage difference over time relative to educational group  
- `remmedia_dif_ocup_diff.png` – Wage difference over time relative to occupational group  

### 3. Survey and Experimental Data Analysis

- Script: `brazil_qualtrics_analysis.R`  
  Produces regression tables from the survey’s observational and experimental components.

- Script: `brazil_qualtrics_conjoint.R`  
  Estimates Average Marginal Component Effects (AMCEs) from the conjoint experiment and exports the results to:  
  `data/qualtrics/brazil/brazil_conjoint_estimates.csv`

- Script: `brazil_cjoint_plots.py`  
  Reads the above CSV file and produces plots of the conjoint results.

**Tables:**
- `information_experiment_brazil.tex` – Impact of wage information on perceived fairness and democratic satisfaction  
- `pca_attitudes_a_brazil.tex` – Regressions of anti-system attitudes on job quality dimensions (I)  
- `pca_attitudes_b_brazil.tex` – Regressions of anti-system attitudes on job quality dimensions (II)  
- `pca_attitudes_c_brazil.tex` – Full model with all job quality dimensions  
- `antisystem_bolsonaro.tex` – OLS models linking anti-system attitudes and behaviors to Bolsonaro vote  
- `antisystem_lula.tex` – OLS models linking anti-system attitudes and behaviors to Lula vote  

**Figures:**
- `cjoint_attitudes.eps` – AMCEs for attitudinal outcomes in conjoint experiment  
- `cjoint_behaviors.eps` – AMCEs for behavioral outcomes in conjoint experiment  

## Requirements

- R 4.x with packages: `stargazer`, `sandwich`, `lfe`, `cjoint`, `MNLpred`, `nnet`
- Python 3.x with `pandas`, `matplotlib`, and `Snakemake`
- LaTeX installation for rendering `.tex` output files

## Citation

Please cite the associated paper if using this code or data:  
Giannoni, Matías. *From the Factory Floor to the Ballot Box: Firm-Based Origins of Brazil's Populist Right*. [Journal Name], [Year].
